//
//  FocusDoctorController.m
//  QuickCure37
//
//  Created by 马文星 on 16/6/18.
//  Copyright © 2016年 Demos. All rights reserved.
//

#import "FocusDoctorController.h"
#import "DoctorCell.h"
#import "DoctorDTO.h"
#import "DoctorInfoController.h"

@interface FocusDoctorController () <UITableViewDataSource,UITableViewDelegate>

/** tableview */
@property (nonatomic, strong) UITableView *tableview;

/** 医生模型 */
@property (nonatomic, strong) NSArray *doctorDTOArray;

@end

@implementation FocusDoctorController

static NSString  *ID = @"CityID";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    [self loadData];
    
//#warning  **************【 测试 】**********************
//
//    DoctorInfoController *infoVC = [[DoctorInfoController alloc] init];
//    
//    [self.navigationController pushViewController:infoVC animated:YES];
}

- (void)setupUI{
    
    
    self.title = @"关注医生";
    
    /*!
     *  添加控件
     */
    [self.view addSubview:self.tableview];
    
    /*!
     *  添加约束
     */
    
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(0);
        make.left.right.bottom.mas_equalTo(0);
        
    }];
}


- (void)loadData{

    DoctorDTO *dto1 = [DoctorDTO doctorWithName:@"王医生" doctorClass:@"副主任医师" hospital:@"上海长征医院" yuyueliang:@"24" flower:@"566" jinqi:@"32" matchedDegree:@"92%"];
     DoctorDTO *dto2 = [DoctorDTO doctorWithName:@"马医生" doctorClass:@"院长" hospital:@"上海协和医院" yuyueliang:@"65" flower:@"89" jinqi:@"232" matchedDegree:@"99%"];
     DoctorDTO *dto3 = [DoctorDTO doctorWithName:@"王医生" doctorClass:@"主任医师" hospital:@"上海男科医院" yuyueliang:@"34" flower:@"123" jinqi:@"433" matchedDegree:@"89%"];
     DoctorDTO *dto4 = [DoctorDTO doctorWithName:@"李医生" doctorClass:@"高级医师" hospital:@"上海长征医院" yuyueliang:@"71" flower:@"645" jinqi:@"43" matchedDegree:@"96%"];
     DoctorDTO *dto5 = [DoctorDTO doctorWithName:@"王医生" doctorClass:@"主任医师" hospital:@"浙大一附院" yuyueliang:@"67" flower:@"345" jinqi:@"100" matchedDegree:@"93%"];
    
    self.doctorDTOArray = @[dto1,dto2,dto3,dto4,dto5];

    [self.tableview reloadData];
}



#pragma mark  - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.doctorDTOArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DoctorCell *cell = (DoctorCell *)[tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        
        cell = [[DoctorCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    
    cell.dto = self.doctorDTOArray[indexPath.row];
    
    return cell;
}


#pragma mark  - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DoctorInfoController *infoVC = [[DoctorInfoController alloc] init];
    
    infoVC.doctorDto = self.doctorDTOArray[indexPath.row];
    
    [self.navigationController pushViewController:infoVC animated:YES];
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


#pragma mark  - Lazy
-(UITableView *)tableview{
    
    if (_tableview == nil) {
        _tableview = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableview.dataSource = self;
        _tableview.delegate = self;
        _tableview.tableFooterView = [UIView new];
        _tableview.rowHeight = 120;
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.backgroundColor = RGBCOLOR(241, 242, 242);

    }
    return _tableview;
    
}

-(NSArray *)doctorDTOArray{
    
    if (_doctorDTOArray == nil) {
        _doctorDTOArray = [[NSArray alloc] init];
    }
    return _doctorDTOArray;
}


@end
